package com.company;

/**
 * @author Administrator
 */
public class 数字三角形 {
    public static void main(String[] args) {
        int n = 10;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n - i; j++) {
                System.out.print("\t");
            }
            for (int k = 1; k <= i; k++) {
                getOdd(k, i);
            }
            System.out.println();
        }
    }

    private static void getOdd(int k, int i) {
        String sign = "***";
        if (i % 2 != 0) {
            int lineNum = i * (i + 1) / 2 + k - i;
            extracted(k, i, sign, lineNum);
        } else {
            int lineNum = i * (i + 1) / 2 - k + 1;
            extracted(k, i, sign, lineNum);
        }
    }

    private static void extracted(int k, int i, String sign, int lineNum) {
        String subStr = lineNum + sign;
        if (subStr.length() > 4) {
            String resStr = subStr.substring(0, subStr.length() - (subStr.length() - 4));
            if (i > k) {
                System.out.print(resStr + "\t");
            } else {
                System.out.print(resStr);
            }
        } else {
            if (i > k) {
                System.out.print(lineNum + sign + "\t" );
            } else {
                System.out.print(lineNum + sign);
            }
        }
    }
}
